package com.xmb.wcapi.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xmb.wcapi.constant.LayTableR;
import com.xmb.wcapi.entity.Inventory;
import com.xmb.wcapi.entity.U8Inventory;
import com.xmb.wcapi.service.IInventoryService;
import com.xmb.wcapi.service.U8InventoryService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;


@RestController
@RequestMapping("manage/select")
public class SelectListController {

    @Autowired
    private U8InventoryService inventoryService;

    @Autowired
    private IInventoryService iInventoryService;

    @GetMapping("/getMaterial")
    public LayTableR getMaterial(Integer page,Integer limit,String cusCode,String invCode){
        if (StringUtils.isEmpty(cusCode)){
            return LayTableR.result(0,0,new ArrayList<>());
        }
        IPage<U8Inventory> in = inventoryService.selectInfoPage(new Page<U8Inventory>(page, limit), cusCode,invCode);
        return LayTableR.result(0,in.getTotal(),in.getRecords());
    }

    @RequestMapping("/getMaterialCus")
    public LayTableR getMaterialCus(Integer page,Integer limit,String cusCode){
        IPage<U8Inventory> in = inventoryService.selectCusInfoPage(new Page<U8Inventory>(page, limit), cusCode);
        return LayTableR.result(0,in.getTotal(),in.getRecords());
    }

    @GetMapping("/getInventory")
    public LayTableR getInventory(Integer page,Integer limit,String cusCode){
        if (StringUtils.isEmpty(cusCode)){
            return LayTableR.result(0,0,new ArrayList<>());
        }
        Page<Inventory> inventoryPage = iInventoryService.page(new Page<Inventory>(page, limit), Wrappers.lambdaQuery(Inventory.class)
//                .eq(Inventory::getMaterial, cusCode)
        );
        return LayTableR.result(0,inventoryPage.getTotal(),inventoryPage.getRecords());
    }

}
